﻿using log4net;
using System;
using System.IO;
using System.Web;

namespace La.Code.Log
{
    /// <summary>
    /// 日志工厂
    /// </summary>
    public class LogFactory
    {
        static LogFactory()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo(System.AppDomain.CurrentDomain.BaseDirectory + "\\log4net.config"));
            //
            FileInfo configFile = new FileInfo(HttpContext.Current.Server.MapPath("/Configs/log4netData.config"));
            //FileInfo configFile = new FileInfo(HttpContext.Current.Server.MapPath("/Configs/log4netCustom.config"));~
            //FileInfo configFile = new FileInfo(HttpContext.Current.Server.MapPath("/Configs/log4net2.config"));
            log4net.Config.XmlConfigurator.Configure(configFile);
        }
        /// <summary>
        /// 记录器
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static LogInfo GetLogger(Type type)
        {
            return new LogInfo(LogManager.GetLogger(type));
        }
        /// <summary>
        /// 记录器
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static LogInfo GetLogger(string str)
        {
            return new LogInfo(LogManager.GetLogger(str));
        }
    }
    public class LogFactoryWindows
    {
        static LogFactoryWindows()
        { 
            log4net.Config.XmlConfigurator.Configure(new FileInfo(System.AppDomain.CurrentDomain.BaseDirectory + "\\log4net.config"));
        }


        /// <summary>
        /// 记录器
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static LogInfo GetLogger(Type type)
        {
            return new LogInfo(LogManager.GetLogger(type));
        }
        /// <summary>
        /// 记录器
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static LogInfo GetLogger(string str)
        {
            return new LogInfo(LogManager.GetLogger(str));
        }
    }

}
